import Cache from '../components/corelib/common/cache'

const MenuList = 'MENU_LIST'
const NavigateTreeData = 'NAVIGATE_TREE_DATA'
const currentUser = 'CURRENT_USER'
const currentPath = 'CURRENT_PATH'

function getValue(key, defaultValue) {
  let cacheObj = Cache.get(key)
  if (cacheObj) {
    return JSON.parse(cacheObj)
  }
  return defaultValue
}

function saveValue(key, value) {
  let _val = ''
  if (value) {
    _val = JSON.stringify(value)
  }
  Cache.save(key, _val)
}

export function saveCurrentUser(value) {
  return saveValue(currentUser, value)
}

export function getCurrentUser() {
  return getValue(currentUser)
}

export function saveCurrentPath(value) {
  return saveValue(currentPath, value)
}

export function getCurrentPath() {
  return getValue(currentPath)
}

export function saveMenuList(value) {
  return saveValue(MenuList, value)
}

export function getMenuList() {
  return getValue(MenuList)
}

export function saveNavigateTreeData(value) {
  return saveValue(NavigateTreeData, value)
}

export function getNavigateTreeData() {
  return getValue(NavigateTreeData)
}
